﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;
using CMS.BLL.Entity;

public partial class Controls_Hotel_ctrPerfectHotel : System.Web.UI.UserControl
{
    private int nCurrentLang = Support.GetCurrentLanguage();
    private int nDefaultLang = Support.GetDefaultLanguage();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDataToHotelPopular();
        }
    }

    private void BindDataToHotelPopular()
    {
        HotelPopular objHotelPopular = new HotelPopular();
        DataTable dtbHotelPopular = objHotelPopular.GetAll();

        rptHotelPopular.DataSource = dtbHotelPopular;
        rptHotelPopular.DataBind();
        rptGroup.DataSource = dtbHotelPopular;
        rptGroup.DataBind();

        lblPerfectJustClick.Text = MultipleLanguage.PERFECTJUSTCLICK_HOTEL[nCurrentLang - 1];
    }

    private int GetCountry()
    {
        int nReturn = ConvertData.ConvertToInt(Request.QueryString["cid"]);
        if (nReturn ==0)
            nReturn = 1;
        return nReturn;
    }

    protected void rptHotelPopular_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label ltrTab = (Label)e.Item.FindControl("ltrTab");
            switch (nCurrentLang)
            {
                case 1:
                    ltrTab.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description1"));
                    break;
                case 2:
                    ltrTab.Text =  ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description2"));
                    break;
                case 3:
                    ltrTab.Text =  ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description3"));
                    break;
            }
        }
    }

    protected void rptHotelPopularContent_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            int nCurrentLanguage = Support.GetCurrentLanguage();
            int nDefaultLanguage = Support.GetDefaultLanguage();
            Literal ltrAddress = (Literal)e.Item.FindControl("ltrAddress");
            HyperLink lnkHotelName = (HyperLink)e.Item.FindControl("lnkHotelName");
            HyperLink lnkReadMore = (HyperLink)e.Item.FindControl("lnkReadMore");
            lnkReadMore.NavigateUrl = Config.ROOT + Pages.FrontEnds.HOTEL_DETAIL + "?" + Config.HOTELID + "=" + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "HotelID")) + "&cid="+ this.GetCountry();
            lnkReadMore.Text = MultipleLanguage.LNK_READMORE[nCurrentLanguage - 1];
            Label lblDuration = (Label)e.Item.FindControl("lblDuration");

            lnkHotelName.NavigateUrl = Config.ROOT + Pages.FrontEnds.HOTEL_DETAIL + "?" + Config.HOTELID + "=" + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "HotelID")) + "&cid=" + this.GetCountry();

            ImageButton imgHotel = (ImageButton)e.Item.FindControl("imgHotel");
            imgHotel.ImageUrl = Config.ROOT + Config.IMAGE_HOTEL_DEFAULT_UPLOAD + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Image"));
            imgHotel.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "HotelID"));

            HotelPopular objHtlPop = new HotelPopular();
            objHtlPop.LoadById(ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "HotelPopularID")));

            Literal ltrHotel = (Literal)e.Item.FindControl("ltrHotel");
            string sInitContent = "";
            switch (nCurrentLang)
            { 
                case 1:
                    lnkHotelName.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title1"));
                    sInitContent = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent1"));
                    ltrAddress.Text = "Address:" + " " + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Address1"));
                    break;
                case 2:
                    lnkHotelName.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title2"));
                    sInitContent = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent2"));
                    ltrAddress.Text = "Address:" + " " + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Address2"));
                    break;
                case 3:
                    lnkHotelName.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title3"));
                    sInitContent = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent3"));
                    ltrAddress.Text = "Dirección:" + " " + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Address3"));
                    break;
            }
            if (sInitContent.Length > 115)
                sInitContent = ConvertData.TruncateString(sInitContent, 115) + "...";
            ltrHotel.Text = sInitContent;

            HtmlImage lblValStarRating = (HtmlImage)e.Item.FindControl("lblValStarRating");
            Support.GetStar(lblValStarRating, ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "StarRating")));
        }
    }

    protected void rptHotel_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        string strCommand = e.CommandName;
        int nID = ConvertData.ConvertToInt(e.CommandArgument);

        switch (strCommand)
        {
            case "image":
                string sDetail = Config.ROOT + Pages.FrontEnds.HOTEL_DETAIL + "?" + Config.HOTELID + "=" + nID + "&cid="+ this.GetCountry();
                Response.Redirect(sDetail);
                break;
        }
    }

    protected void rptHotelPopularContent_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        string strCommand = e.CommandName;
        int nID = ConvertData.ConvertToInt(e.CommandArgument);

        switch (strCommand)
        {
            case "image":
                string sDetail = Config.ROOT + Pages.FrontEnds.HOTEL_DETAIL + "?" + Config.HOTELID + "=" + nID + "&cid="+ this.GetCountry();
                Response.Redirect(sDetail);
                break;
        }
    }

    protected void rptGroup_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        int nPageCount = 0;
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Repeater rptHotelPopularContent = (Repeater)e.Item.FindControl("rptHotelPopularContent");
            HyperLink lnkPerfectMore = (HyperLink)e.Item.FindControl("lnkPerfectMore");
            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "HotelPopularID"));


            Hotel objHotel = new Hotel();
            DataTable dtbHotel = new DataTable();
            //dtbHotel = objHotel.Search(3, 0, "", 0, 0, nID, 0, 0, 0, "", nDefaultLang, nCurrentLang, -1, 1, 1, 3, ref nPageCount);
            dtbHotel = objHotel.Search(3, "", 0, 0, nID, 0, 1, 3, ref nPageCount);
            rptHotelPopularContent.DataSource = dtbHotel;
            rptHotelPopularContent.DataBind();

            lnkPerfectMore.Text = MultipleLanguage.GETMOREHOTEL[nCurrentLang - 1];
            lnkPerfectMore.NavigateUrl = "~/HotelCatelogy.aspx?" + Config.HOTEL_POPULAR + "=" + nID + "&cid=" + GetCountry();
        }
    }
}